/**
 * Copyright &copy; 2017-2020 <a href="http://www.fosung.com/">FosungFrame</a> All rights reserved.
 */
package com.fosung.frame.modules.partyassessmentinfo.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.fosung.frame.common.config.Global;
import com.fosung.frame.common.persistence.Page;
import com.fosung.frame.common.utils.StringUtils;
import com.fosung.frame.common.web.BaseController;
import com.fosung.frame.modules.partyassessmentinfo.entity.PartyAssessmentInfo;
import com.fosung.frame.modules.partyassessmentinfo.service.PartyAssessmentInfoService;

/**
 * 党组织考核信息Controller
 * 
 * @author wu
 * @version 2017-08-30
 */
@Controller
@RequestMapping(value = "${adminPath}/partyassessmentinfo/partyAssessmentInfo")
public class PartyAssessmentInfoController extends BaseController {

	@Autowired
	private PartyAssessmentInfoService partyAssessmentInfoService;

	@ModelAttribute
	public PartyAssessmentInfo get(@RequestParam(required = false) String id) {
		PartyAssessmentInfo entity = null;
		if (StringUtils.isNotBlank(id)) {
			entity = partyAssessmentInfoService.get(id);
		}
		if (entity == null) {
			entity = new PartyAssessmentInfo();
		}
		return entity;
	}

	@RequiresPermissions("partyassessmentinfo:partyAssessmentInfo:view")
	@RequestMapping(value = { "list", "" })
	public String list(PartyAssessmentInfo partyAssessmentInfo, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<PartyAssessmentInfo> page = partyAssessmentInfoService.findPage(new Page<PartyAssessmentInfo>(request, response), partyAssessmentInfo);
		model.addAttribute("page", page);
		return "modules/partyassessmentinfo/partyAssessmentInfoList";
	}

	@RequiresPermissions("partyassessmentinfo:partyAssessmentInfo:view")
	@RequestMapping(value = "form")
	public String form(PartyAssessmentInfo partyAssessmentInfo, Model model) {
		model.addAttribute("partyAssessmentInfo", partyAssessmentInfo);
		return "modules/partyassessmentinfo/partyAssessmentInfoForm";
	}

	@RequiresPermissions("partyassessmentinfo:partyAssessmentInfo:edit")
	@RequestMapping(value = "save")
	public String save(PartyAssessmentInfo partyAssessmentInfo, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, partyAssessmentInfo)) {
			return form(partyAssessmentInfo, model);
		}
		partyAssessmentInfoService.save(partyAssessmentInfo);
		addMessage(redirectAttributes, "保存党组织考核信息成功");
		return "redirect:" + Global.getAdminPath() + "/partyassessmentinfo/partyAssessmentInfo/?repage";
	}

	@RequiresPermissions("partyassessmentinfo:partyAssessmentInfo:edit")
	@RequestMapping(value = "delete")
	public String delete(PartyAssessmentInfo partyAssessmentInfo, RedirectAttributes redirectAttributes) {
		partyAssessmentInfoService.delete(partyAssessmentInfo);
		addMessage(redirectAttributes, "删除党组织考核信息成功");
		return "redirect:" + Global.getAdminPath() + "/partyassessmentinfo/partyAssessmentInfo/?repage";
	}

	/**
	 * 跳转到党组织积分说明
	 * 
	 * @param homeApprove
	 * @param model
	 * @return
	 */
	@RequiresPermissions("approve:activityApprove:view")
	@RequestMapping(value = "toQueryPartyAssessmentInfo")
	public String toQueryPartyAssessmentInfo(HttpServletRequest request, HttpServletResponse response,Model model) {
		String orgId = request.getParameter("orgId");
		String mode = request.getParameter("mode");
		model.addAttribute("orgId", orgId);
		model.addAttribute("mode", mode);
		return "modules/approve/partyAssessmentInfo";
	}

	/**
	 * 查看党组织积分说明
	 * 
	 * @param homeApprove
	 * @param model
	 * @return
	 */
	@RequiresPermissions("approve:activityApprove:view")
	@RequestMapping(value = "queryPartyAssessmentInfo")
	@ResponseBody
	public List<PartyAssessmentInfo> queryPartyAssessmentInfo(PartyAssessmentInfo partyAssessmentInfo, Model model) {
		List<PartyAssessmentInfo> list = partyAssessmentInfoService.queryPartyAssessmentInfo(partyAssessmentInfo);
		return list;
	}

}